package com.google.code.irouter.utils;

import com.google.appengine.api.datastore.Key;
import com.google.code.irouter.model.Log;

public final class LogUtil {
	
	public static enum TYPE {
		BATCH, CORE, PORTAL
	}

	public static void error(TYPE type, Class<?> sender, Key solution, String message) {
		write(solution, type.name(), "ERROR", sender.getName(), message, null);
	}
	
	public static void error(TYPE type, Class<?> sender, Key solution, String message, Exception exception) {
		exception.printStackTrace();
		write(solution, type.name(), "ERROR", sender.getName(), message, exception.getMessage());
	}

	public static void info(TYPE type, Class<?> sender, Key solution, String message) {
		write(solution, type.name(), "INFO", sender.getName(), message, null);
	}

	public static void warn(TYPE type, Class<?> sender, Key solution, String message,
			Exception exception) {
		write(solution, type.name(), "WARN", sender.getName(), exception.getMessage(), exception.getMessage());
	}
	
	public static void warn(TYPE type, Class<?> sender, Key solution, String message) {
		write(solution, type.name(), "WARN", sender.getName(), message, null);
	}
	
	private static void write(Key solution, String category, String level, String sender, String message, String stack) {
		System.out.println(message);
		System.out.println(stack);
//		try {
//			Log log = new Log();
//			log.setCategory(category);
//			log.setLevel(level);
//			log.setSolution(solution);
//			log.setSender(sender);
//			log.setMessage(message);
//			log.setStack(stack);
//			log.pushCreatDate();
//			ModelUtil.save(log);
//		} catch (Exception exception) {
//			exception.printStackTrace();
//		}
	}

}
